<?php

namespace Modules\Api\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Modules\Api\Service\MaintainShopService;

class MaintainShopController extends BaseController
{
    /**
     *  门店服务分类列表
     *
     *  2019 12 09
     */
    public function shop_maintain_list(Request $request)
    {
        $arr_input = $request->all();
        $res = MaintainShopService::get_list($arr_input);

        return response_json($res);
    }

    /**
     *  选择保养后预生成订单
     *
     *  2019 12 09
     */
    public function order_preview(Request $request)
    {
        $arr_input = $request->all();
        $user = api_user();
        $arr_input['user_realname'] = $user->realname; //用户真实姓名
        $arr_input['user_phone'] = $user->phone; //用户id

        $res = MaintainShopService::order_preview($arr_input);

        return response_json($res);
    }

    /**
     * 获取维修服务商品列表
     *
     * 2019 12 10
     */
    public function get_repair_goods_list(Request $request)
    {
        $arr_input = $request->all();

        $res = MaintainShopService::get_repair_goods_list($arr_input);

        return response_json($res);
    }

    /**
     * 获取维修服务商品详情
     *
     * 2019 12 10
     */
    public function get_repair_goods_detail(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id
        $res = MaintainShopService::get_repair_goods_detail($arr_input);

        return response_json($res);
    }

    /**
     *  选择服务后预生成订单
     *
     *  2019 12 09
     */
    public function repair_order_preview(Request $request)
    {
        $arr_input = $request->all();
        $user = api_user();
        $arr_input['user_realname'] = $user->realname; //用户真实姓名
        $arr_input['user_phone'] = $user->phone; //用户id

        $res = MaintainShopService::repair_order_preview($arr_input);

        return response_json($res);
    }


    /**
     * 生成服务订单
     *
     * 2019 12 10
     */
    public function generate_repair_order(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        shiwu_start();
        $res = MaintainShopService::generate_repair_order($arr_input);
        shiwu_end($res);

        return response_json($res);
    }

    /**
     * 生成保养订单
     *
     * 2019 12 10
     */
    public function generate_maintain_order(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        shiwu_start();
        $res = MaintainShopService::generate_maintain_order($arr_input);
        shiwu_end($res);

        return response_json($res);
    }

    /**
     * 支付订单
     *
     * 2019 12 10
     */
    public function repair_pay_order(Request $request)
    {
        $n_id = $request->input('order_id');
        $order_number = $request->input('order_number');
        $n_uid = api_user_id(); //用户id
        $a = ['data' => json_encode([12])];
        DB::table('test')->insert($a);
        // $res = MaintainShopService::check_wxfw_pay_order_api($n_id, $n_uid);//支付前查询
        $res2 = MaintainShopService::notify_for_wxfw($order_number);//支付回调订单处理
        // $res3 = MaintainShopService::order_result_for_wxfw($n_id);//支付后查询
        return response_json([$res2]);
        //return response_json([$res,$res2, $res3]);
    }

    /**
     * 获取订单列表（保养，服务）
     *
     * 2019 12 12
     */
    public function get_repair_store_order(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        $res = MaintainShopService::get_repair_store_order($arr_input);

        return response_json($res);
    }

    /**
     * 订单详情
     *
     * 2019 12 13
     */
    public function get_repair_store_order_info(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        $res = MaintainShopService::get_repair_store_order_info($arr_input);

        return response_json($res);
    }

    /**
     * 修改订单状态（取消订单，申请退款，确认处理）
     *
     * 2019 12 13
     */
    public function handle_repair_order(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        shiwu_start();
        $res = MaintainShopService::handle_repair_order($arr_input);
        shiwu_end($res);

        return response_json($res);
    }

    /**
     * 删除订单
     *
     * 2019 12 13
     */
    public function del_order(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        $res = MaintainShopService::del_order($arr_input);

        return response_json($res);
    }

    /**
     * 获取售后订单列表
     */
    public function get_sale_order(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id(); //用户id

        $res = MaintainShopService::get_sale_order((array)$arr_input);

        return response_json($res);
    }
}